package com.bw.mvvm_common.network.inteceptor;

import com.bw.mvvm_common.utils.SPUtils;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * @author KK
 * @description:
 * @date :2021/10/13 15:20
 * token拦截器
 */
public class TokenInterceptor implements Interceptor {


    @Override
    public Response intercept(Chain chain) throws IOException {
        Request request = chain.request();
        String token = SPUtils.readToken();
        Request.Builder builder = new Request.Builder();
        builder.url(request.url());
        builder.headers(request.headers());
        builder.addHeader("token",token);
        builder.post(request.body());
        return chain.proceed(builder.build());
    }
}
